package com.luobo.yfh.vo.respone;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

@ApiModel(value = "响应参数")
public class Result<T> implements Serializable {

    /** 状态码 */
    @ApiModelProperty(value ="状态码 1成功 0失败" ,required = true,example="1")
    private int code;

    /** 返回内容*/
    @ApiModelProperty(value ="消息" ,required = true,example="成功!")
    private String message;

    /**数据对象*/
    @ApiModelProperty(value ="数据对象" ,required = true)
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result() {
    }

    public Result( int code,String message) {
        this.code = code;
        this.message = message;
    }

    public Result( int code,String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result<T> success(T obj){
        Result<T> result = new Result<>(1,"成功!");
        result.setData(obj);
        return result;
    }

    public static Result success(){
         return new Result<>(1,"成功!");
    }

    public static Result error(){
        return new Result(0,"失败!");
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
